//
//  TableShowWKWebCell+Config.swift
//  CooperSwift
//
//  Created by 计海峰 on 2021/12/9.
//

import UIKit
import RxSwift
import WebKit

public extension TableShowWKWebCell {
    
    /// 写布局
    func layoutViews() {
        guard let cellModel = self.info as? TableShowWKWebCellModel else { return }
        // 执行一次配置
        if !cellModel.isConfigDone {
            cellModel.isConfigDone = true
            cellModel.once(webview, cell: self)
        }
        cellModel.every(webview, cell: self)
//        webview.load()
    }
    
}

// MARK: - WKNavigationDelegate
//extension TableShowWKWebCell : WKNavigationDelegate {
//    
//    public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
////        webView.evaluateJavaScript("document.documentElement.style.webkitTouchCallout='none';", completionHandler: nil)
////        webView.evaluateJavaScript("document.documentElement.style.webkitUserSelect='none';", completionHandler: nil)
////        let injectionJSString = """
////            "var script = document.createElement('meta');"
////            "script.name = 'viewport';"
////            "script.content=\"width=device-width, initial-scale=1.0,maximum-scale=1.0, minimum-scale=1.0, user-scalable=no\";"
////            "document.getElementsByTagName('head')[0].appendChild(script);"
////        """
////        webView.evaluateJavaScript(injectionJSString, completionHandler: nil)
//    }
//    
//    public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
//        
//    }
//    
//    public func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
//        decisionHandler(.allow)
//    }
//    
//}

// MARK: - WKUIDelegate
//extension TableShowWKWebCell : WKUIDelegate {
//    public func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
//
//    }
//
//    public func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) {
//
//    }
//
//    public func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) {
//
//    }
//}

// MARK: - scrollView delegate
//extension TableShowWKWebCell : UIScrollViewDelegate {
    
//    public func scrollViewDidScroll(_ scrollView: UIScrollView) {
//        
//        if !showSourceHint { return }
//        if scrollView.contentOffset.y < -40 {
//            if scrollView.contentOffset.y > -60 {
//                sourceHintLB.alpha = (-scrollView.contentOffset.y - 40)/20
//            }
//        }else {
//            sourceHintLB.alpha = 0
//        }
//        sourceHintLB.y = scrollView.contentOffset.y
//    }
    
//}
